
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module http.kefu
* @author: Hjava
* @description: HTTP模块的新客服模块
* @since: 2018-07-22 15:52:33
*/
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var http_core_1 = __webpack_require__(/*! _http/http.core */ "./src/core/http/http.core.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var analytics_1 = __webpack_require__(/*! _util/analytics */ "./src/core/utils/analytics.ts");
exports.default = {
    /**
     * 获取正在服务的会话列表
     * @param options {}
     * @return {*}
     */
    getServingSessionList: function (options) {
        var succ = options.success;
        options.success = function (res) {
            if (res.rescode === 0) {
                res.data.chatlist = res.data.chatlist.map(function (session) {
                    session.lastMsg = protocol_1.default.Response.fromBase64(session.lastMsg);
                    return session;
                });
            }
            succ(res);
        };
        http_core_1.default.request('/kefu/api/chatlist/v3/serving', options);
    },
    getDoneSessionList: function (options) {
        var succ = options.success;
        options.success = function (res) {
            if (res.rescode === 0) {
                res.data.chatlist = res.data.chatlist.filter(function (session) {
                    return session.lastMsg;
                }).map(function (session) {
                    if (session.lastMsg) {
                        session.lastMsg = protocol_1.default.Response.fromBase64(session.lastMsg);
                    }
                    return session;
                });
            }
            succ(res);
        };
        http_core_1.default.request('/kefu/api/chatlist/v3/done', options);
    },
    /**
     * 获取历史消息
     * @param options {bid|peerUid|mid|limit}
     * @return {*}
     */
    getHistoryMessages: function (options) {
        var succ = options.success;
        options.success = function (res) {
            var messages;
            try {
                if (res.rescode === 0 && res.data.res.length > 0) {
                    messages = protocol_1.default.Response.fromBase64(res.data.res[0]);
                    succ({
                        next: res.data.next,
                        messageData: messages.msgs
                    });
                    analytics_1.default.report({
                        nm: 'message_fetch_kefu_history_success',
                        val: {
                            chat: options && options.data ? options.data.u : '0',
                            type: 1,
                            count: messages.msgs.length,
                            mids: messages.msgs.map(function (m) {
                                return m.msgId.toString();
                            })
                        }
                    });
                }
                else {
                    succ({
                        next: 0,
                        messageData: []
                    });
                }
            }
            catch (e) {
                succ({
                    next: 0,
                    messageData: []
                });
            }
        };
        options.error = function (e) {
            analytics_1.default.report({
                nm: 'message_fetch_kefu_history_error',
                val: {
                    code: e && e.request && e.request.status ? e.request.status : void 0
                }
            });
        };
        http_core_1.default.request('/msg/api/kefu/v1/history/chat/kf/mergebyuid/channel', options);
        analytics_1.default.report({
            nm: 'message_fetch_kefu_history_start',
            val: {
                chat: options && options.data ? options.data.u : '0',
                type: 1
            }
        });
    },
    getHistoryMessagesByRange: function (options) {
        var succ = options.success;
        options.success = function (res) {
            var messages;
            try {
                if (res.rescode === 0 && res.data.res.length > 0) {
                    messages = protocol_1.default.Response.fromBase64(res.data.res[0]);
                    succ({
                        next: res.data.next,
                        messageData: messages.msgs
                    });
                    analytics_1.default.report({
                        nm: 'message_fetch_kefu_history_success',
                        val: {
                            chat: options && options.data ? options.data.u : '0',
                            type: 1,
                            count: messages.msgs.length,
                            mids: messages.msgs.map(function (m) {
                                return m.msgId.toString();
                            })
                        }
                    });
                }
                else {
                    succ({
                        next: 0,
                        messageData: []
                    });
                }
            }
            catch (e) {
                succ({
                    next: 0,
                    messageData: []
                });
            }
        };
        options.error = function (e) {
            analytics_1.default.report({
                nm: 'message_fetch_kefu_history_error',
                val: {
                    code: e && e.request && e.request.status ? e.request.status : void 0
                }
            });
        };
        http_core_1.default.request('/msg/api/kefu/v1/history/chat/kf/byrange/channel', options);
        analytics_1.default.report({
            nm: 'message_fetch_kefu_history_start',
            val: {
                chat: options && options.data ? options.data.u : '0',
                type: 2
            }
        });
    },
    getHistoryMessagesToC: function (options) {
        if (options.data) {
            options.data.svid = 415;
            options.data.id = options.data.id || '9223372036854775806';
        }
        http_core_1.default._history('/msg/api/kefu/v1/history/chat/byid/channel', options, constant_1.LOG_FROM_SOURCE.KEFU);
    },
    getRemoteSessionListToC: function (options) {
        http_core_1.default._kefuChatlist('/kefu/api/info/v1/getChatlist/byChannelId', options);
    },
    getOfflineMessages: function (options) {
        if (options.data) {
            options.data.svid = 415;
        }
        http_core_1.default._offline('/msg/api/kefu/v1/offline/chat', options);
    }
};


//# sourceURL=webpack://MTDX/./src/core/http/http.kefu.ts?